public class Game01 {
	public static void main(String[] args) {
		int[] child=new int[500];
		for(int i=0;i<child.length;i++) {
			child[i]=1;
		}
		int j=0,count=0;
		while(total(child)>=1) {
			if(child[j]==1) {
				count++;
				if(count%3==0) {
					child[j]=0;
				}
			}
			j++;
			if(j==child.length) {
				j=0;
			}
		}
		System.out.println(j);
	}
	
	static int total(int[] child) {
		int sum=0;
		for(int i=0;i<child.length;i++) {
			sum+=child[i];
		}
		return sum;
	}
}